package com.nvn.washiodriver.network.ws;

import java.io.IOException;
import java.util.LinkedHashMap;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.content.Context;

import com.nvn.washiodriver.network.NetworkUtils;
import com.nvn.washiodriver.network.WebServiceCommunicatorListener;
import com.nvn.washiodriver.utils.Statics;

@SuppressLint("DefaultLocale")
public class UpdateNoteWSControl extends BaseWSControl {
	private String orderId;
	private String notes;

	public UpdateNoteWSControl(Context context,
			WebServiceCommunicatorListener listener, String orderId, String notes) {
		super(context, listener, WebServiceFlag.UPDATE_NOTE);
		this.orderId = orderId;
		this.notes = notes;
	}

	@Override
	protected Object doInBackground(Void... params) {
		// Get local database

		String url = Statics.WASHIO_WS_URL + "order/driver/notes/" + orderId;
		LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
		parameters.put("notes", notes);
		try {
			String respone = NetworkUtils.doPostRequest(url, parameters);
			
			try {
				JSONObject jsonObject = new JSONObject(respone);

				return jsonObject.getString("error");
			} catch (JSONException e) {
				return "Successful";
			}

		} catch (ClientProtocolException e) {
			mError = "Cannot connect to network";
			e.printStackTrace();
		} catch (IOException e) {
			mError = "Cannot connect to network";
			e.printStackTrace();
		}
		return null;
	}


}
